<template>
  <div id="app">
    <div class="loading" v-if="dataLoading">
      <van-loading size="24px" vertical>加载中...</van-loading>
    </div>
    <LayoutPage v-else />
    <div class="download" v-if="['ios', 'android', 'vivo'].indexOf(from) == -1">
      <button @click="download">下载GankeAPP解锁全部图鉴功能</button>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { mapState } from "vuex";
// 布局组件
import LayoutPage from "@/components/layout/LayoutPage.vue";
export default {
  components: { LayoutPage },
  computed: {
    ...mapState("data", ["dataLoading", "alldataLoading", "testaaa"]),
  },
  data() {
    return {
      from: "",
    };
  },
  watch: {},
  created() {
    this.setFontSize();
    this.from = window.from;
    window.addEventListener("resize", this.setFontSize);
    if (this.$route.name !== "Loading") {
      this.$router.push("/loading");
    }
  },
  methods: {
    setFontSize() {
      let designW = 360; // 设计图宽度
      let bodyW = document.body.clientWidth; // 文档宽度
      bodyW = bodyW > 500 ? 500 : bodyW;
      let fontSize = (bodyW / designW) * 100;
      Vue.prototype.fontSize = fontSize;
      document.documentElement.style.fontSize = fontSize + "px"; // 设置全局文字大小
      Vue.prototype.viewHeight = window.screen.availHeight * 1.2;
    },
    download() {
      window.injectedAll.download();
    },
  },
};
</script>

<style lang="scss">
body,
html,
#app {
  padding: 0;
  margin: 0;
  background: #000000;
  font-family: Arial, Helvetica, sans-serif;
  width: 100%;
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #333;
  user-select: none;
}

#app {
  font-size: 0.12rem;
  display: flex;
  flex-direction: column;
}
.loading {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.van-overlay {
  background-color: rgba(0, 0, 0, 0.5) !important;
}

.download-alert {
  border-radius: 10px !important;
}

.download {
  position: fixed;
  bottom: 0.15rem;
  left: 0;
  right: 0;
  margin: auto;
  z-index: 3;
  padding: 0 0.15rem;
  button {
    display: block;
    width: 100%;
    max-width: calc(500px - 0.3rem);
    margin: 0 auto;
    height: 0.4rem;
    line-height: 0.4rem;
    text-align: center;
    background: #ff8a69;
    box-shadow: 0px 2px 8px 0px rgba(195, 112, 88, 0.32);
    border-radius: 0.6rem;
    font-size: 0.14rem;
    color: #fff;
    border: none;
  }
}

input,
button {
  outline: none;
  padding: 0;
  margin: 0;
  -moz-appearance: textfield;
  &::-webkit-outer-spin-button,
  &::-webkit-inner-spin-button {
    -webkit-appearance: none;
  }
}
</style>
